﻿using DevExpress.XtraGrid.Demos.util;
using Luna小店.DTO;
using Luna小店.service;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Luna小店.版型
{
    public class 版型Model
    {
        private UserTaskDTO userTaskDTO;

        public UserTaskDTO UserTaskDTO { get => userTaskDTO; set => userTaskDTO = value; }

        public 版型Model() {

        }

        #region 标准版检索
        /// <summary>
        /// 特征值检索,多条，用户选择
        /// </summary>
        /// <param name="features"></param>
        /// <returns></returns>
        public DataTable 标准版检索ByFeature(Dictionary<String, String> features)
        {
            return CADService.标准版检索ByFeature(features);  //  TODO
        }
        #endregion

        #region 标准版改版上传
        public void 创建任务() { 
            //this.userTaskDTO,任务service上传
            //  CAD_ID要传入
        }

        //  上传文件，并且生成标签

        #endregion

        #region 沿用之前的版
        /// <summary>
        /// 返单号检索
        /// </summary>
        /// <param name="ORDER_NO"></param>
        /// <returns></returns>
        public UserTaskDTO 沿用之前的版ByOrderNo(String ORDER_NO) {
            //  任务服务中返回
            return TaskQueryFacadeService.GetUserTaskDTOByOrderNo(ORDER_NO);
        }

        /// <summary>
        /// 特征值检索,多条，用户选择
        /// </summary>
        /// <returns></returns>
        public List<UserTaskDTO> 沿用之前的版ByFeature(String STYLE_ID,String STYLE_FIT_CD,String CUSTOMER_ID)
        {
            //  任务服务中返回
            return TaskQueryFacadeService.GetUserTaskDTOBy特征值(STYLE_ID,STYLE_FIT_CD,CUSTOMER_ID);
        }
        #endregion

        #region 任务处理
        /// <summary>
        /// 版型确认后调用
        /// </summary>
        /// <param name="TEMPLATE_ID">常量就行，不用传参</param>
        /// <param name="CAD_ID">Form记录，传参</param>
        /// <param name="ORDER_NO">Form记录，传参</param>
        /// <returns></returns>
        public 版型Model build任务(String TEMPLATE_ID, String CAD_ID,String ORDER_NO) {
            String SERIAL_NUMBER = FunctionHelper.generateBillNo("t_remark", "serial_number", "TB", "000000");//生成流水号  //  TODO,调用生成方法
            this.UserTaskDTO = new UserTaskDTO(TEMPLATE_ID, SERIAL_NUMBER, CAD_ID);
            //  其他杂七杂八信息自己填
            return this.build订单(ORDER_NO).build订单款式();
        }

        /// <summary>
        /// 构建订单信息
        /// </summary>
        /// <param name="ORDER_NO"></param>
        private 版型Model build订单(String ORDER_NO)
        {
            //  从OrderService根据ORDER_NO查询订单信息
            DataRow dr = OrderService.GetOidSidCidByOno(ORDER_NO);
            this.UserTaskDTO.build订单(dr["ORDER_ID"].ToString(), dr["STYLE_ID"].ToString(), dr["CUSTOMER_ID"].ToString());   //  传单
            return this;
        }

        /// <summary>
        /// 构建款式信息
        /// </summary>
        private 版型Model build订单款式()
        {
            //根据this.userTaskDTO.STYLE_ID，在StyleService中查询款式信息
            DataRow dr = StyleService.GetRefsidSFCBySid(this.UserTaskDTO.STYLE_ID);
            this.UserTaskDTO.build款式信息(dr["REF_STYLE_ID"].ToString(), dr["STYLE_FIT_CD"].ToString());
            return this;
        }
        #endregion


    }
}
